<template>
    <div class="common achieveAndCert">
        <innerCommon 
            :location="location"
        >
            <template slot="left">
                <span>成绩列表</span>
                <majorModule
                    @submitSearch="submitSearch"
                ></majorModule>
            </template>
            <div slot="table">
                <a-table 
                    size="middle"
                    :columns="columns" 
                    :data-source="list" 
                    :pagination="pagination"
                    :rowKey="record=>record.id"
                    @change="changePage"
                    :locale="{'emptyText': '暂无数据'}"
                    bordered>
                    <div slot="action" slot-scope="index,record"  class="tableAction">
                        <span @click="toDetail(record)">成绩详情</span>
                    </div>
                </a-table>
            </div>
        </innerCommon>
    </div>
</template>
<script>
const columns=[
    {
        title: '序号',
        dataIndex: 'index',
        width:70
    },{
        title: '课程考试名称',
        dataIndex: 'paperTitle',
    },{
        title: '课程名称',
        dataIndex: 'title',
    },{
        title: '所属专业',
        dataIndex: 'major',
    },{
        title: '所属教学模块',
        dataIndex: 'module',
    },{
        title: '考试总分',
        dataIndex: 'totalScore',
    },{
        title: '合格分数线',
        dataIndex: 'passScore',
    },{
        title: '参加考试人数',
        dataIndex: 'joinedNum',
    },{
        title: '不合格人数',
        dataIndex: 'failedNum',
    },{
        title: '合格人数',
        dataIndex: 'passedNum',
    },{
        title: '证书数量',
        dataIndex: 'certNum',
    },{
        title: '操作',
        scopedSlots: { customRender: 'action' },
        width:100
    }
]
import innerCommon from "@/components/common/innerCommon"
import majorModule from "@/components/common/majorModule"
import {getAchieveListApi} from "@/request/api"
export default {
    name:"assessment",
    components:{innerCommon,majorModule},
    created(){
        if(this.$route.query.page){
            this.searchInfo.page=this.$route.query.page
            this.pagination.current=this.$route.query.page
        }
        this.location=[{
            name:"教学课堂管理",
            path:''
        },{
            name:"成绩与证书",
            path:'/achieveAndCert'
        }]
        this.init()
    },
    data(){
        return{
            location:[],
            columns,
            list:[],
            pagination:{pageSize:10,total:0,current:1},
            searchInfo:{
                page:1,
                pageSize:10,
                keyword:''
            },
        }
    },
    methods:{
        init(){
            this.getToken(getAchieveListApi,this.searchInfo,res=>{
                this.list=res.data.rows.map((item,index)=>({
                    ...item,
                    'index':(this.searchInfo.page-1)*10+index+1,
                    'paperTitle':item.chapters[0].tasks[0].title,
                    'major':item.majors.filter(value=>value.pid==0)[0].name,
                    'module':item.majors.filter(value=>value.pid!=0)[0].name,
                }))
                this.pagination.total=res.data.count
            })
        },
        changePage(data){
            this.searchInfo.page=data.current
            this.pagination.current=data.current
            this.init()
        },
        toDetail(data){
            this.$router.push({path:'/achievementDetail',query:{id:data.id,'name':data.title,page:this.searchInfo.page}})
        },
        submitSearch(data){
            this.searchInfo.keyword=data.keyword
            this.searchInfo.page=1
            this.pagination.current=1
            if(data.moduleId&&data.moduleId!=0){
                this.searchInfo.majorId=data.moduleId
            }else{
                this.searchInfo.majorId=data.majorId==0?null:data.majorId
            }
            this.init()
        }
        
    }
}
</script>